/**
 * Created with IntelliJ IDEA.
 * User: 12629
 * Date: 2022/2/18
 * Time: 18:40
 * Description:
 */
public class TestDemo {

    public static int fac(int n) {
        if(n == 1) {
            return 1;
        }
        int tmp = n*fac(n-1);
        return tmp;
    }

    //写一个方法，打印1-9的所有数字
    public static void print(int n) {
        if(n == 1) {
            System.out.println(n);
        }else {
            print(n-1);
            System.out.println(n);
        }
    }

    public static void printf(int n) {
        if(n < 10) {
            System.out.println(n);
        }else {
            printf(n/10);
            System.out.println(n%10);
        }
    }

    //123的每一位加起来的和
    public static int sumFunc(int n) {
        if(n < 10) {
            return n;
        }else {
            int ret = sumFunc(n/10)+n%10;
            return ret;
        }
    }

    /**
     * 面试的时候  不要写递归的斐波那契实现
     * 原因是：重复计算的数据太多了  效率会很低
     * @param n
     * @return
     */
    public static int count = 0;
    public static int fib(int n) {
        if(n == 1 || n == 2) {
            count++;
            return 1;
        }
        return fib(n-1)+fib(n-2);
    }


    public static int fib2(int n) {
        if(n == 1 || n == 2) {
            return 1;
        }
        int f1 = 1;
        int f2 = 1;
        int f3 = 0;
        for (int i = 3; i <= n; i++) {
            f3 = f1+f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }

    public static void main(String[] args) {
        /*System.out.println(fib2(1));
        System.out.println(fib2(2));
        System.out.println(fib2(3));*/
        System.out.println(fib(4));
        System.out.println(count);
    }

    public static void func(int i) {
        if(i == 1) return;
        func(i-1);
    }

    public static void main4(String[] args) {
        func(10);
    }

    public static int add(int x,int y) {
        return x+y;
    }

    public static long add(int x,int y,int z) {
        return x+y+z;
    }

    public static double add(double x,double y) {
        return x+y;
    }

    public static void main3(String[] args) {
        int a = 10;
        System.out.println(add(1, 2));
        System.out.println(add(1.2,6.7));
    }

//    public static void sum(int x1,int x2) {
//        System.out.println(x1+x2);
//    }

    public static void main2(String[] args) {

        //sum(add(1,2),6);

        //sum(1,2);
       /* int ret2 = add(11,12)+9;
        System.out.println(ret2);*/

//        int ret3 = sum(11,12)+9;
//        System.out.println(ret2);
    }

    public static void main1(String[] args) {
      /*  byte a = 10;
        byte b = 20;
        int ret = add(a,b);
        System.out.println(ret);
        int ret2 = add(11,12)+9;
        System.out.println(ret2);
        //int x = a;*/
    }
}
